var mclient = require('mongodb').MongoClient;
var client = require("../../DAOImpl/mongodb");
var dataConfig = require("../../config/database.json");
var host = dataConfig.host;
var database = dataConfig.db;
var db = new client(host, database);
var googlemap = require('../../private/googleService/service');


/*
 * req.body:
 * kind: c/d
 * "_id": req.body._id;
 * "cus_phone": req.body.cus_phone,
 * "cus_pwd": req.body.cus_pwd,
 * "sex": req.body.sex,
 * "nickname":req.body.nickname
 */
function mongotest(req, res, next) {
	var document = new Object();
	var result = new Object();
	
	var cus1 = ['nickname','sex'];
	var cus2 = ['cus_nickname','cus_sex'];
	
	for(var index in req.body){
		var i = 0;
		while(index != cus1[i] && i < cus1.length){
			i++;
		}		
		if(i == cus1.length){
			document[index] = req.body[index]
		}
		else{
			document[cus2[i]] = req.body[index];
		}
	};
	delete document['cus_nickname'];
	console.log(document);
	res.send(document);
	return next();
}
exports.services = [ mongotest ];